//
//  HWChenjiaoDonTaiViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/8/30.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWChenjiaoDonTaiViewController.h"
#import "HWClinchDealCell.h"
#import "HWDynamicModel.h"
#import "HWAccountDetailsViewController.h"

@interface HWChenjiaoDonTaiViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(strong,nonatomic) UITableView *mainaTableVie;

@property(strong,nonatomic) NSString *p; //分页
@property(strong,nonatomic) NSString *max_p; // 最大分页
@property(strong,nonatomic) NSString *pandunSr;
@property(strong,nonatomic) NSMutableArray  *dataMuArr;

@end

@implementation HWChenjiaoDonTaiViewController

-(UITableView *)mainaTableVie {
    
    if (_mainaTableVie == nil
        ) {
        
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        
        
    }
    return   _mainaTableVie ;
}





- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor redColor];
    // 设置UI
    [self setupUI];
    
  
    
}









- (void)setupUI {
    
    self.navigationItem.title = @"成交动态";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.mainaTableVie];
    [self addrefreshControl];
    
}


#pragma  mark ---- 添加刷新

- (void)addrefreshControl {

    self.mainaTableVie.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(underRefresh)];

    [self.mainaTableVie.mj_header beginRefreshing];

    self.mainaTableVie.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(onRefresh)];
}

// 下拉刷新
- (void)underRefresh {



    self.p = @"1";

    
    NSString *uidStr = [NSString stringWithFormat:@"%@",[HWLocallyStoredData getLoginUserID]];
    
    NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];

   
    self.dataMuArr = [[NSMutableArray alloc]init];
    
//
    NSDictionary *parametes = @{
                                       @"p" :self.p,
                                       @"ios" : @"1",
                                       @"ct" :  @"app",
                                       @"ac" : @"trade_trends",
                            
        
                                       };
    
    
  

       [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {

           // [SVProgressHUD dismiss];
           [self.mainaTableVie.mj_header endRefreshing];
           [self.mainaTableVie.mj_footer endRefreshing];


           NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];

           if ([codeStr intValue] == 1) {

              self.dataMuArr = [HWDynamicModel  mj_objectArrayWithKeyValuesArray:response[@"data"]];
               self.p = [NSString stringWithFormat:@"%@",response[@"p"]];
               self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
               
               

             


           } else if ([codeStr intValue] == 0) {
               
               
               
               
           }
           [self.mainaTableVie reloadData];


       } failure:^(NSString *error) {
           [self.mainaTableVie.mj_header endRefreshing];
           [self.mainaTableVie.mj_footer endRefreshing];


       }];


}

// 上拉加载

- (void)onRefresh {



    int p = [self.p intValue];

    int max_p = [self.max_p intValue];

     if (p > max_p) {
        [MBProgressHUD showError:@"没有更多数据，请待会在上拉加载"];
        [self.mainaTableVie.mj_header endRefreshing];
        [self.mainaTableVie.mj_footer endRefreshing];
                            
        return ;

      }


    NSDictionary *parametes = @{
                                    @"p" :self.p,
                                     @"ios" : @"1",
                                     @"ct" :  @"app",
                                     @"ac" : @"trade_trends",
                                   
                                            };
         
    

        [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {

             // [SVProgressHUD dismiss];
             [self.mainaTableVie.mj_header endRefreshing];
             [self.mainaTableVie.mj_footer endRefreshing];


             NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];

             if ([codeStr intValue] == 1) {



//
//                 NSMutableArray *mutableArr = [HWTradingModel  mj_objectArrayWithKeyValuesArray:response[@"data"]];
//

//                 for (int i = 0; i < mutableArr.count; i++) {
//                     [self.shujudataMuArr addObject:mutableArr[i]];
//
//                 }

                 self.p = [NSString stringWithFormat:@"%@",response[@"p"]];
                 self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
                 [self.mainaTableVie reloadData];


             }
            [self.mainaTableVie reloadData];


         } failure:^(NSString *error) {
             [self.mainaTableVie.mj_header endRefreshing];
             [self.mainaTableVie.mj_footer endRefreshing];


         }];




}














- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return  self.dataMuArr.count;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID = @"cellID";
    HWClinchDealCell *cell =  [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell =  [[NSBundle mainBundle]loadNibNamed:@"HWClinchDealCell" owner:nil options:nil].lastObject;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor whiteColor];
    cell.dataModel = self.dataMuArr[indexPath.row];
    
    return  cell;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return  86;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    HWDynamicModel   *model =   self.dataMuArr[indexPath.row];
    HWAccountDetailsViewController *accountDetails = [[HWAccountDetailsViewController alloc]init];
    accountDetails.idStr = model.id;
    [self.navigationController pushViewController:accountDetails animated:YES];
    
    
    

}







@end
